package com.clh.seckill.config;

import com.clh.seckill.pojo.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author cailinhu
 * @Description 线程私有化
 * @Date 2022/1/20 15:57
 * @Version 1.0
 */
public class UserContext {
    public static ThreadLocal<User> threadLocal=new ThreadLocal<>();
    public static ThreadLocal<HttpServletResponse> threadResponse=new ThreadLocal<>();
    public static ThreadLocal<HttpServletRequest> threadRequest=new ThreadLocal<>();

    public static HttpServletResponse getResponse() {
        return threadResponse.get();
    }

    public static void setResponse(HttpServletResponse response) {
        threadResponse.set(response);
    }

    public static HttpServletRequest getRequest() {
        return threadRequest.get();
    }

    public static void setRequest(HttpServletRequest request) {
        threadRequest.set(request);
    }

    public static void setUser(User user){
        threadLocal.set(user);
    }
    public static User getUser(){
        return threadLocal.get();
    }
}
